package com.lplb.api.admin.service.impl.platform;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lplb.api.admin.mapper.AdminRoleMapper;
import com.lplb.api.admin.model.dto.AdminRoleDTO;
import com.lplb.api.admin.model.entity.AdminRole;
import com.lplb.api.admin.model.vo.AdminRoleVO;
import com.lplb.api.admin.service.platform.IAdminRoleService;
import com.lplb.common.core.result.R;
import com.lplb.common.core.service.BaseIServiceImpl;
import com.lplb.common.core.utils.BeanDtoVoUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 角色表 管理端服务接口实现
 * </p>
 *
 * @author ws
 * @date 2020-07-21
 */
@RestController
public class AdminRoleServiceImpl  extends BaseIServiceImpl<AdminRoleMapper, AdminRole> implements IAdminRoleService {


     /**
     *  分页查询
     */
     @Override
     public R<IPage<AdminRoleVO>> findPage() {
         Page<AdminRole> page = this.page(this.getPage(), new LambdaQueryWrapper<AdminRole>()
                 .orderByAsc(AdminRole::getCreateTime)
         );
         return R.success(BeanDtoVoUtil.pageVo(page, AdminRoleVO.class));
     }


    /**
    *  查询所有
    */
    @Override
    public R<List<AdminRoleVO>> findList() {
        List<AdminRole> list = this.list(new LambdaQueryWrapper<AdminRole>()
                .orderByAsc(AdminRole::getCreateTime)
        );
        return R.success(BeanDtoVoUtil.listVo(list, AdminRoleVO.class));
     }



     /**
     * ID 查询
     *
     * @return
     */
     @Override
     public R<AdminRoleVO> findId(@RequestParam String id) {
         AdminRole adminRole = this.getById(id);
         return R.success(BeanDtoVoUtil.convert(adminRole,AdminRoleVO.class));
     }


     /**
     * 新增
     */
     @Override
     public R<Void> add(@RequestBody @Validated AdminRoleDTO dto) {
         this.save(dto.convert(AdminRole.class));
         return R.success();
     }


     /**
     *  编辑
     */
     @Override
     public R<Void> upd(@RequestBody @Validated AdminRoleDTO dto) {
         this.updateById(dto.convert(AdminRole.class));
         return R.success();
     }


     /**
     *  ID 删除
     */
     @Override
     public R<Void> removeId(@RequestParam String id) {
         this.removeById(id);
         return R.success();
     }

 }

